package ace.module.captcha.sms.sdk.core.feign.impl;

import ace.cmp.core.model.R;
import ace.cmp.openfeign.security.oauth2.core.config.FeignInternalServerOauth2SecurityConfig;
import ace.module.captcha.sms.api.CaptchaSmsApi;
import ace.module.captcha.sms.sdk.core.constant.SdkConstant;
import ace.module.common.api.annotation.ApiRemoteProxyPriority;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author caspar
 * @date 2023/3/17 15:49
 */
@FeignClient(
    name = "${spring.cloud.openfeign.client.captchaSmsFeign.name:" + SdkConstant.FEIGN_SERVICE_NAME + "}",
    contextId = "captchaSmsFeign",
    path = CaptchaSmsFeign.PATH,
    configuration = FeignInternalServerOauth2SecurityConfig.class,
    primary = false
)
@ApiRemoteProxyPriority
public interface CaptchaSmsFeign extends CaptchaSmsApi {

  String PATH = "${spring.cloud.openfeign.client.captchaSmsFeign.path:/captcha-sms/rpc/captcha-sms}";

  @Operation(summary = "发送短信验证码", description = "data=验证码")
  @PostMapping(path = "/send")
  R<String> send(
      @Valid @NotNull @RequestParam("captchaSmsAppId") Long captchaSmsAppId,
      @Valid @NotBlank @RequestParam("phoneNumber") String phoneNumber,
      @Valid @NotBlank @RequestParam("code") String code);

  @Operation(summary = "验证短信验证码", description = "0-验证通过 1-验证不通过 2-没有配置")
  @GetMapping(path = "/verify")
  R<Void> verify(
      @Valid @NotNull @RequestParam("captchaSmsAppId") Long captchaSmsAppId,
      @Valid @NotBlank @RequestParam("phoneNumber") String phoneNumber,
      @Valid @NotBlank @RequestParam("code") String code);

  @Operation(summary = "验证短信验证码", description = "0-验证通过 1-验证不通过 2-没有配置")
  @GetMapping(path = "/verify/appkey")
  R<Void> verify(
      @Valid @NotNull @RequestParam("captchaSmsAppKey") String captchaSmsAppKey,
      @Valid @NotBlank @RequestParam("phoneNumber") String phoneNumber,
      @Valid @NotBlank @RequestParam("code") String code);
}
